<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="format-detection" content="telephone=no" />
    <title>停租</title>
    <link rel="stylesheet" href="../../css/reset.css">
    <style>
        body {
            width: 100%;
            background-color: #fff;
            font-size: 0.25rem;
            height: auto;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
            font-family: Helvetica;
            color: rgba(24, 24, 24, 0.65);
        }

        .showdetial {
            width: 100%;
            box-sizing: border-box;
            height: auto;
        }

        .showli {
            display: flex;
            display: -webkit-flex;
            flex-direction: column;
            -webkit-flex-direction: column;
        }

        .showli li {
            padding: 0 0.24rem;
            padding-top: 0.12rem;
            background-color: #fff;
            box-sizing: border-box;
        }

        .showli li p {
            width: 100%;
            height: 0.8rem;
            display: flex;
            display: -webkit-flex;
            justify-content: space-between;
            -webkit-justify-content: space-between;
            align-items: center;
            -webkit-align-items: center;
        }

        .buttonsmall {
            background-color: #fff;
            text-align: center;
            padding-bottom: 0.3rem;
        }

        .buttonsmall button {
            color: #181818;
            font-size: 0.26rem;
            width: 6.9rem;
            height: 0.88rem;
            background-color: #ffd203;
            outline: none;
            border: none;
            border-radius: 0.1rem;
        }

        .checkbox {
            width: 0.44rem;
            height: 0.44rem;
            border: 1px solid gray;
            border-radius: 0.44rem;
            position: relative;
        }

        .checkbox .circle {
            background: url("../../image/checknew.png") center no-repeat;
            background-size: cover;
            position: relative;
            left: -0.3rem;
            top: -0.3rem;
            width: 0.43rem;
            height: 0.43rem;
            display: none;
            margin: 0.3rem;
        }

        .checked .circle {
            display: block;
        }

        #stopNum {
            border: none;
            outline: none;
            width: 1.5rem;
            height: 0.6rem;
            font-size: 0.28rem;
            text-align: center;
            background-color: rgba(0, 0, 0, 0);
        }
    </style>
</head>

<body>
    <div class="showdetial">
        <ul class="showli">
            <li>
                <p style="border-bottom: 1px solid #e2e2e2;">
                    <span>
                        退单名称
                    </span>
                    <span class="machineName">

                    </span>
                </p>
            </li>
            <li>
                <p>
                    <span>
                        合约金额
                    </span>
                    <span id="unitMoney">
                        0 CNY
                    </span>
                </p>
            </li>
            <li>
                <p>
                    <span>
                        到手BTC算力
                    </span>
                    <span class="powerNumber">

                    </span>
                </p>
            </li>
            <li class="showBhpPowerNum" style="display: none;">
                <p>
                    <span>
                        BHP参配算力
                    </span>
                    <span class="powerBhpNumber">

                    </span>
                </p>
            </li>
            <li style="display: inline-block;width: 100%;height: 0.2rem;background-color: #f7f7f7;">
            </li>
            <li>
                <p>
                    <span>
                        退单算力
                    </span>
                    <span
                        style="display: flex; display: -webkit-flex;align-items: center;-webkit-align-items: center;font-size: 0.26rem;">
                        <span id="reduceNum"
                            style="font-size: 0.4rem;margin-right: 0.1rem;width: 0.76rem;height: 0.7rem;display: flex;display: -webkit-flex;align-items: center;justify-content: center;background-color: #f7f7f7;border-radius: 0.02rem;">
                            －
                        </span>
                        <span style="background-color: #f7f7f7;">
                            <input type="text" oninput="this.value=this.value.replace(/\D/g, '')" value="0"
                                name="stopNum" id="stopNum">
                        </span>
                        <span id="addNum"
                            style="font-size: 0.4rem;margin-left: 0.1rem;margin-right: 0.2rem;width: 0.76rem;height: 0.7rem;display: flex;display: -webkit-flex;align-items: center;justify-content: center;background-color: #f7f7f7;border-radius: 0.02rem;">
                            ＋
                        </span>
                        份
                    </span>
                </p>
            </li>
            <li
                style="display: inline-block;width: 100%;height: 0.7rem;background-color: #f7f7f7;display: flex;display: -webkit-flex;align-items: center;justify-content: flex-end;">
                <span>
                    算力提示: 1份 = <span class="bastNum">1</span><span class="bastUnit">T</span> 算力
                </span>
            </li>
            <li id="chooseRentType" data-choose="threeMonth">
                <p>
                    <span>
                        退单金额
                    </span>
                    <span style="display: flex; display: -webkit-flex;align-items: center;-webkit-align-items: center;">
                        <span id="chooseText"
                            style="width: auto;height: 0.88rem;color: #ffd203;display: flex;display: -webkit-flex;align-items: center;">
                            00 CNY
                        </span>
                    </span>
                </p>
            </li>
            <li id="showLi" style="display: inline-block;width: 100%;height: 0.1rem;background-color: #f7f7f7;">

            </li>
            <li class="isShowbhpc" style="display: none;">
                <p>
                    <span>
                        退单方式
                    </span>
                </p>
            </li>
            <li class="isShowbhpc chooseType" style="display: none;">
                <p
                    style="display: flex;display: -webkit-flex;justify-content: space-between;-webkit-justify-content: space-between;align-items: center;-webkit-align-items: center">
                    <span>
                        我要CNY(
                        <span class="unitMoney">
                            00 CNY
                        </span>
                        )
                    </span>
                    <span class="checkbox checked" data-method="BCNY">
                        <span class="circle" style="color:#daa464;"></span>
                    </span>
                </p>
            </li>
            <li id="showMoney" style="border-top: 1px solid #e5e5e5;">
                <p style="color: #616161;" class="tipsText">
                    当前退还的CNY金额将直接退到资产余额中,请前往【我的】-【我的资产】中查看
                </p>
            </li>
        </ul>
    </div>
    <div class="buttonsmall" style="padding-top: 0.64rem;">
        <button id="checkRent">
            立即退单
        </button>
    </div>
    <script src="../../script/autosize.js"></script>
    <script src="../../script/fastclick.js"></script>
    <script src="../../script/jquery_three_two_one.js"></script>
    <script src="../../script/app.js"></script>
    <script>
        apiready = function () {
            var app = new APP();
            app.headerMap();
            if (app.ST != "ios") {
                $("#stopNum").css("height", "0.7rem");
            }
            var account = app.getAccount();
            app.togClass(".chooseType", "checked", ".checkbox");
            var showBhpc = api.pageParam.bhpcisshow;
            var machdata = api.pageParam.machineData;
            var orderID = machdata.orderId;
            var rentNum = machdata.num;
            var refour = /([0-9]+\.[0-9]{4})[0-9]*/;
            var limitRentUnit = " T";
            if (machdata.currencyCode != "BTC") {
                limitRentUnit = " M";
            }
            var unitPrice = app.accDiv(machdata.totalDeposit, machdata.num);//单价
            var bhpPower = machdata.bhpPower;//BHP参数配置
            var addRewardPower = app.moreAccAdd(machdata.futuresPower, machdata.regularPower, machdata.floatPower, machdata.pePower);
            var textTips = app.accMul(machdata.computingPower, rentNum) + limitRentUnit + "(" + app.accMul(machdata.basePower, rentNum) + limitRentUnit + "+" + app.accMul(addRewardPower, rentNum) + limitRentUnit + ")"
            $(".powerNumber").text(textTips);
            $(".bastNum").text(machdata.basePower);
            $(".todaymoney").text(machdata.totalDeposit);
            $(".bastUnit").text(limitRentUnit);
            $("#stopNum").val(rentNum);
            if (machdata.isBhpPos == 1) {
                $(".showBhpPowerNum").show();
                $(".powerBhpNumber").text(app.accMul(rentNum, bhpPower) + "T");
            }
            $(".machineName").text(machdata.productName);
            if (machdata.paymentCurrencyCode == "BCNY" || machdata.paymentCurrencyCode == "BHPC") {
                unitPrice = 3000;
                $("#unitMoney").text(app.accMul(3000, machdata.num) + "   " + "OTC余额");
                $(".unitMoney").text(app.accMul(3000, machdata.num) + "   " + "CNY");
                $("#chooseText").text(app.accMul(3000, machdata.num) + "   " + "CNY");
                if (machdata.paymentCurrencyCode == "BCNY") {
                    unitPrice = app.accDiv(machdata.totalDeposit, machdata.num);
                    $("#unitMoney").text(app.sliceNum(machdata.totalDeposit, 2) + "   " + "OTC余额");
                    $(".unitMoney").text(app.sliceNum(machdata.totalDeposit, 2) + "   " + "CNY");
                    $("#chooseText").text(app.sliceNum(machdata.totalDeposit, 2) + "   " + "CNY");
                }
            } else if (machdata.paymentCurrencyCode == "USDT") {
                $("#unitMoney").text(app.sliceNum(machdata.totalDeposit, 4) + "   " + machdata.paymentCurrencyCode);
                $(".unitMoney").text(app.sliceNum(machdata.totalDeposit, 4) + "   " + machdata.paymentCurrencyCode);
                $("#chooseText").text(app.sliceNum(machdata.totalDeposit, 4) + "   " + machdata.paymentCurrencyCode);
            } else {
                $("#unitMoney").text(machdata.totalDeposit + "   " + machdata.paymentCurrencyCode);
                $(".unitMoney").text(machdata.totalDeposit + "   " + machdata.paymentCurrencyCode);
                $("#chooseText").text(machdata.totalDeposit + "   " + machdata.paymentCurrencyCode);
            }
            if (showBhpc == "BCNY") {
                $(".isShowbhpc").show();
            } else {
                $("#chooseRentType").css({
                    marginBottom: "0"
                });
                $("#showLi").css({
                    display: "none"
                });
            }
            if (machdata.paymentCurrencyCode == "BCNY" || machdata.paymentCurrencyCode == "BHPC") {
                $(".tipsText").text("当前退还的CNY将直接退到CNY资产中,请前往【我的】-【我的资产】中查看");
            } else if (machdata.paymentCurrencyCode == "CNY") {
                $(".tipsText").text("当前退还的CNY将直接退到CNY资产中,请前往【我的】-【我的资产】中查看");
            } else {
                $(".tipsText").text('当前退还的' + machdata.paymentCurrencyCode + '将直接退到' + machdata.paymentCurrencyCode + '资产中,请前往【我的】-【我的资产】中查看');
            }
            $("#checkRent").on("click", function (params) {
                var reduceNumberText = $("#stopNum").val();
                app.ajaxPro({
                    url: "order/return-loss",//请求退单减少算龄
                    values: {
                        token: account.token,
                        order_id: orderID,
                        num: reduceNumberText
                    },
                    openFlower: true
                }, function (ret) {
                    if (ret.code == 200) {
                        var param = {
                            dtype: "dialog5",
                            data: {
                                title: "温馨提示",
                                text: ret.message,
                                btns: [{
                                    name: "再想想",
                                    event: "NoIthink"
                                },
                                {
                                    name: "我要退单",
                                    event: "YesSure"
                                }
                                ]
                            }
                        };
                        app.dialog(param);
                    } else {
                        app.toast(ret.message);
                    }
                })
            });
            $("#reduceNum").click(function () {
                var numRectNum = Number($("#stopNum").val());
                numRectNum--;
                if (numRectNum <= 0) {
                    return
                }
                $("#stopNum").val(numRectNum);
                var moneyTotalRe = String(app.accMul(numRectNum, unitPrice));
                if (machdata.paymentCurrencyCode == "USDT") {
                    $("#chooseText").text(moneyTotalRe.replace(refour, "$1") + machdata.paymentCurrencyCode);
                    $(".unitMoney").text(moneyTotalRe.replace(refour, "$1") + machdata.paymentCurrencyCode);
                } else {
                    $("#chooseText").text(app.changeTwoDecimal_f(moneyTotalRe) + (machdata.paymentCurrencyCode == "BCNY" || machdata.paymentCurrencyCode == "BHPC" ? "CNY" : machdata.paymentCurrencyCode));
                    $(".unitMoney").text(app.changeTwoDecimal_f(moneyTotalRe) + (machdata.paymentCurrencyCode == "BCNY" || machdata.paymentCurrencyCode == "BHPC" ? "CNY" : machdata.paymentCurrencyCode));
                }
                if (machdata.isBhpPos == 1) {
                    $(".powerBhpNumber").text(app.accMul(numRectNum, bhpPower) + "T");
                }
            });
            $("#addNum").click(function () {
                var maxRectNum = Number($("#stopNum").val());
                maxRectNum++;
                if (maxRectNum > rentNum) {
                    return
                }
                $("#stopNum").val(maxRectNum);
                var moneyTotalAdd = String(app.accMul(maxRectNum, unitPrice));
                if (machdata.paymentCurrencyCode == "USDT") {
                    $("#chooseText").text(moneyTotalAdd.replace(refour, "$1") + machdata.paymentCurrencyCode);
                    $(".unitMoney").text(moneyTotalAdd.replace(refour, "$1") + machdata.paymentCurrencyCode);
                } else {
                    $("#chooseText").text(app.changeTwoDecimal_f(moneyTotalAdd) + (machdata.paymentCurrencyCode == "BCNY" || machdata.paymentCurrencyCode == "BHPC" ? "CNY" : machdata.paymentCurrencyCode));
                    $(".unitMoney").text(app.changeTwoDecimal_f(moneyTotalAdd) + (machdata.paymentCurrencyCode == "BCNY" || machdata.paymentCurrencyCode == "BHPC" ? "OTC余额" : machdata.paymentCurrencyCode));
                }
                if (machdata.isBhpPos == 1) {
                    $(".powerBhpNumber").text(app.accMul(numRectNum, bhpPower) + "T");
                }
            });

            $("#stopNum").on("keyup", function () {
                var thisVal = Number($(this).val());
                if (thisVal > rentNum) {
                    thisVal = rentNum;
                };
                $(this).val(thisVal);
                var moneyTotal = String(app.accMul(thisVal, unitPrice));
                if (machdata.paymentCurrencyCode == "USDT") {
                    $("#chooseText").text(moneyTotal.replace(refour, "$1") + machdata.paymentCurrencyCode);
                    $(".unitMoney").text(moneyTotal.replace(refour, "$1") + machdata.paymentCurrencyCode);
                } else {
                    $("#chooseText").text(app.changeTwoDecimal_f(moneyTotal) + (machdata.paymentCurrencyCode == "BCNY" || machdata.paymentCurrencyCode == "BHPC" ? "CNY" : machdata.paymentCurrencyCode));
                    $(".unitMoney").text(app.changeTwoDecimal_f(moneyTotal) + (machdata.paymentCurrencyCode == "BCNY" || machdata.paymentCurrencyCode == "BHPC" ? "OTC余额" : machdata.paymentCurrencyCode));
                }
                if (machdata.isBhpPos == 1) {
                    $(".powerBhpNumber").text(app.accMul(numRectNum, bhpPower) + "T");
                }
            })
            $("#stopNum").on("blur", function () {
                var thisValNum = Number($(this).val());
                if (thisValNum == 0) {
                    $(this).val(1);
                    var moneyTotalNum = app.accMul(1, unitPrice);
                    $("#chooseText").text(app.changeTwoDecimal_f(moneyTotalNum) + (machdata.paymentCurrencyCode == "BCNY" || machdata.paymentCurrencyCode == "BHPC" ? "CNY" : machdata.paymentCurrencyCode));
                    $(".unitMoney").text(app.changeTwoDecimal_f(moneyTotalNum) + (machdata.paymentCurrencyCode == "BCNY" || machdata.paymentCurrencyCode == "BHPC" ? "OTC余额" : machdata.paymentCurrencyCode));
                    if (machdata.isBhpPos == 1) {
                        $(".powerBhpNumber").text(app.accMul(numRectNum, bhpPower) + "T");
                    }
                }
            })
            app.listen("YesSure", function () {
                var chooseBackType = $(".chooseType").find(".checked").data("method");
                var reduceNumber = $("#stopNum").val();
                app.ajaxPro({
                    url: "order/return",
                    values: {
                        token: account.token,
                        orderId: orderID,
                        num: reduceNumber
                    },
                    openFlower: true
                }, function (ret) {
                    if (ret.code == 200) {
                        app.toast("退单成功！");
                        app.trigger("stop_rent_success");
                        app.tout(500, function () {
                            app.closeW();
                        });
                        $(this).unbind("click");
                    } else {
                        app.toast(ret.message);
                    }
                })
            });
        };
    </script>
</body>

</html>